<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        img {
            width: auto;
            height: auto;
        }
    </style>
</head>
<body>
<a href="../images/4.jpg" id="ak"><img src="../images/5.jpg" alt="" id="im"></a>
<script>
    document.getElementById("im").onclick = function () {
        this.src = document.getElementById("ak").href;
        return false;
    };
</script>
</body>
</html>